Return to start page
Systems/Gui/Struct Dialog Button.j
1 library AStructSystemsGuiDialogButton requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable, ALibraryCoreStringConversion
2
3 /// @todo Should be a part of @struct ADialogButton, vJass bug.
4 function interface ADialogButtonAction takes ADialogButton dialogButton returns nothing
5
6 struct ADialogButton
7 //start members
8 private ADialog m_dialog
9 private string m_text
10 private integer m_shortcut
11 private boolean m_isQuitButton
12 private boolean m_doScoreScreen
13 private ADialogButtonAction m_action
14 //members
15 private integer m_index
16 private button m_button
17 private trigger m_trigger
18
19 //! runtextmacro optional A_STRUCT_DEBUG("\"ADialogButton\"")
20
21 //start members
22
23 public method dialog takes nothing returns ADialog
24 return this.m_dialog
25 endmethod
26
27 public method text takes nothing returns string
28 return this.m_text
29 endmethod
30
31 public method shortcut takes nothing returns integer
32 return this.m_shortcut
33 endmethod
34
35 public method isQuitButton takes nothing returns boolean
36 return this.m_isQuitButton
37 endmethod
38
39 public method doScoreScreen takes nothing returns boolean
40 return this.m_doScoreScreen
41 endmethod
42
43 public method action takes nothing returns ADialogButtonAction
44 return this.m_action
45 endmethod
46
47 //members
48
49 public method index takes nothing returns integer
50 return this.m_index
51 endmethod
52
53 //methods
54
55 /// Usually you do not need this method. It is used by @struct ADialog.
56 public method addButton takes nothing returns nothing
57 if (not this.m_isQuitButton) then
58 set this.m_button = DialogAddButton(this.m_dialog.dialog(), HighlightShortcut(this.m_text, this.m_shortcut, "ffffcc00"), this.m_shortcut)
59 else
60 set this.m_button = DialogAddQuitButton(this.m_dialog.dialog(), this.m_doScoreScreen, HighlightShortcut(this.m_text, this.m_shortcut, "ffffcc00"), this.m_shortcut)
61 endif
62 call this.createTrigger()
63 endmethod
64
65 public method removeButton takes nothing returns nothing
66 call this.destroyTrigger()
67 endmethod
68
69 private static method triggerActionRunDialogButtonAction takes nothing returns nothing
70 local trigger triggeringTrigger = GetTriggeringTrigger()
71 local ADialogButton this = AHashTable.global().handleInteger(triggeringTrigger, "this")
72 call this.dialog().setDisplayedByButton(false) // Do not clear the dialog automatically (dialog().clear()) since it can be shown again with same buttons.
73 call this.m_action.execute(this)
74 set triggeringTrigger = null
75 endmethod
76
77 private method createTrigger takes nothing returns nothing
78 local event triggerEvent
79 local triggeraction triggerAction
80 //create always since it sends the dialog that it's hidden again.
81 //if (this.m_action != 0) then
82 set this.m_trigger = CreateTrigger()
83 set triggerEvent = TriggerRegisterDialogButtonEvent(this.m_trigger, this.m_button)
84 set triggerAction = TriggerAddAction(this.m_trigger, function thistype.triggerActionRunDialogButtonAction)
85 call AHashTable.global().setHandleInteger(this.m_trigger, "this", this)
86 set triggerEvent = null
87 set triggerAction = null
88 //endif
89 endmethod
90
91 public static method create takes ADialog usedDialog, string text, integer shortcut, boolean isQuitButton, boolean doScoreScreen, ADialogButtonAction action returns thistype
92 local thistype this = thistype.allocate()
93 //start members
94 set this.m_dialog = usedDialog
95 set this.m_text = text
96 set this.m_shortcut = shortcut
97 set this.m_isQuitButton = isQuitButton
98 set this.m_doScoreScreen = doScoreScreen
99 set this.m_action = action
100 //members
101 set this.m_index = usedDialog.addDialogButtonInstance(this)
102
103 return this
104 endmethod
105
106 private method destroyTrigger takes nothing returns nothing
107 //if (this.m_action != 0) then
108 call AHashTable.global().destroyTrigger(this.m_trigger)
109 set this.m_trigger = null
110 //endif
111 endmethod
112
113 public method onDestroy takes nothing returns nothing
114 call this.m_dialog.removeDialogButtonByIndex(this.m_index)
115 if (this.m_button != null) then
116 set this.m_button = null //can not be destroyed
117 call this.destroyTrigger()
118 endif
119 endmethod
120 endstruct
121
122 endlibrary